#
# For Qt
#
find_package(Qt4 REQUIRED)

add_definitions(${QT_DEFINTIONS})

link_directories(${QT_LIB_DIR})

include_directories(${QT_INCLUDE_DIR})

include(${QT_USE_FILE})

set(bandleader_srcs
    ChangeChord.cpp
    ChordView.cpp
    Cursor.cpp
    DeleteBar.cpp
    DeleteRow.cpp
    Document.cpp
    InsertBar.cpp
    InsertBarAfter.cpp
    MainWindow.cpp
    MidiPlayer.cpp
    OpenRow.cpp
    main.cpp
)

set(bandleader_libs
    ${QT_LIBRARIES}
    improv
)

set(bandleader_moc_hdrs
    ChordView.h
    Cursor.h
    Document.h
    MainWindow.h
    MidiPlayer.h
)

qt4_wrap_cpp(bandleader_moc_srcs ${bandleader_moc_hdrs})

include_directories(.. .)

if(WIN32)
    add_definitions(-DVISUAL)
endif(WIN32)

if(MINGW)
    add_custom_command(OUTPUT
                       ${CMAKE_CURRENT_BINARY_DIR}/bandleader.o
                       COMMAND windres.exe
                                -I${CMAKE_CURRENT_SOURCE_DIR}
                                -i${CMAKE_CURRENT_SOURCE_DIR}/bandleader.rc 
                                -o ${CMAKE_CURRENT_BINARY_DIR}/bandleader.o
    )
    set(bandleader_srcs
        ${bandleader_srcs}
        ${CMAKE_CURRENT_BINARY_DIR}/bandleader.o
    )
    set(CMAKE_CXX_FLAGS "-mwindows")
endif(MINGW)

add_executable(bandleader ${bandleader_srcs} ${bandleader_moc_srcs})

target_link_libraries(bandleader ${bandleader_libs})

add_subdirectory(improv)
add_subdirectory(playmidi)


if(WIN32)
    # for local builds
    file(GLOB icon_files ${CMAKE_CURRENT_SOURCE_DIR}/icons/*)
    foreach(icon_file ${icon_files})
        configure_file(${icon_file}
                       ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
    endforeach(icon_file)

    install(TARGETS bandleader
            RUNTIME DESTINATION .
    )
    install(DIRECTORY icons/ DESTINATION .
            PATTERN ".svn" EXCLUDE)
else(WIN32)
    install(TARGETS bandleader
            RUNTIME DESTINATION bin)
    install(DIRECTORY icons DESTINATION share
            PATTERN ".svn" EXCLUDE)
endif(WIN32)

